<?php
///
namespace app\Controller;

///
use lxsphp\App;
use lxsphp\Core\Mvc\Controller;

/**
 * Class Site
 *
 * @package app\Controller
 */
class Site extends Controller
{
	/**
	 *
	 */
	public function actionHome()
	{
		///
		$ref = new \ReflectionClass(__CLASS__);
		foreach ($ref->getMethods() as $m) {
			/**
			 * @var \ReflectionMethod $m
			 */
			$method = $m->getName();
			if (strpos($method, "test") !== false) {
				echo "<pre>";
				echo "-------------------------------[ ", $method, " ]-------------------------------";
				echo "<pre>";

				///
				call_user_func_array(array($this, $method), array());
			}
		}
	}

	/**
	 *
	 */
	public function action500()
	{
		echo "500";
	}

	/**
	 * @param $data
	 */
	public function dump($data)
	{
		echo "<pre>";
		print_r($data);
		echo "</pre>";
	}

	/**
	 *
	 */
	public function testModel()
	{
		/**
		 * @var \app\Model\Site\Bar $model
		 */
		$model = App::$I->getModel('app\Model\Site\Bar');
		$model->test();
	}

	/**
	 *
	 */
	public function testPdo()
	{
		///
		$pdo = App::getPdo()->getPdo();
		$sth = $pdo->prepare("SHOW TABLES");
		$sth->execute();
		$data = $sth->fetchAll(\PDO::FETCH_COLUMN);
		$this->dump($data);
	}

	/**
	 *
	 */
	public function testDb()
	{
		///
		try {
			/**
			 * @var \app\Db\Order $db
			 */
			$db = App::$I->getDb('app\Db\Order');
			$db->qb->where('id=:id');

			///
			$data = $db->getRow([':id' => 1]);
			$this->dump($data);

			///
			$db->qb->where('id=:id');
			$data = $db->getRow([':id' => 2]);
			$this->dump($data);
		} catch (\Exception $e) {
			$this->dump($e);
		}
	}

	/**
	 *
	 */
	public function testRedis()
	{
		/**
		 * @var \Redis $redis
		 */
		$redis = App::getRedis();
		$data = $redis->get("abc");
		$this->dump($data);
	}

	/**
	 *
	 */
	public function testSmarty()
	{
		///
		$this->display('home');
	}
}

/**
 * Class abc
 *
 * @package app\Controller
 */
class abc extends \Exception
{

}
